/**
 * Copyright (C), 2015-2021, XXX有限公司
 * FileName: FocusActivity
 * Author: Gxjkz
 * Date: 2021/7/19 9:54
 * Description: 关注
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package com.niuxiaofa.newlaw.Activity;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Base.BaseActivity;
import com.niuxiaofa.newlaw.Base.RefreshInterface;
import com.niuxiaofa.newlaw.Bean.FollowFansBean;
import com.niuxiaofa.newlaw.Network.MePresenter;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.RecyclerViewHelp;
import com.niuxiaofa.newlaw.adapter.FocusAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * @ClassName: FocusActivity
 * @Description: java类作用描述
 * @Author: Gxjkz
 * @Date: 2021/7/19 9:54
 */
public class FocusActivity extends BaseActivity implements RefreshInterface.Refresh, MePresenter.interface_followfans {


    FocusAdapter focusAdapter;


    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;


    int current=1;

    int type;

    Integer memberId;

    List<FollowFansBean.DataDTO.RecordsDTO> listEntities = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.activity_focus;
    }


    @Override
    protected void initData() {

        refreshinterface=new RefreshInterface(this);

        if (getIntent().getStringExtra("memberId") != null) {
            memberId = Integer.parseInt(getIntent().getStringExtra("memberId"));
        }

        MePresenter.followfans(memberId, type, current, this);

        focusAdapter = new FocusAdapter(listEntities, new FocusAdapter.Onclick() {
            @Override
            public void onclick(int c) {

            }
        });


        RecyclerViewHelp.setRecycler(recyclerview, 10).setAdapter(focusAdapter);

    }

    @Override
    public void refresh() {
        current=1;
        MePresenter.followfans(memberId, type, current, this);
    }

    @Override
    public void loadmore() {
        current++;
        MePresenter.followfans(memberId, type, current, this);
    }

    @Override
    public void getResponse(FollowFansBean u) {
        if (u.getCode() == 1) {
            if (refreshLayout!=null){
                refreshLayout.finishRefresh();
                refreshLayout.finishLoadMore();
            }


            if (current == 1) {
                listEntities.clear();
            }
            listEntities.addAll(u.getData().getRecords());

            focusAdapter.notifyDataSetChanged();

        }
    }
}